var app = getApp()
Page({
  data: {
    num: 10,
    count: -1,
    page: 0,
    list: [],
    hasmoreData: true,
    hiddenloading: true,
  },
  onLoad: function (options) {
    this.getList()
  },
  onPullDownRefresh: function () {
    this.setData({ num: 10, count: -1, page: 0, list: [], hasmoreData: true, hiddenloading: true })
    this.getList();
    console.log('刷新数据')
    wx.stopPullDownRefresh()
  },
  onReachBottom: function () {
    console.log('加载更多')
    this.setData({ hiddenloading: false })
    this.getList()
  },
  getList: function () {
    var that = this
    if (that.data.count != -1 && that.data.page * that.data.num >= that.data.count) {
      that.setData({ hasmoreData: false, hiddenloading: true })
      return
    }
    app.post('链接', { page: that.data.page }, function (res) {//这边是我自己的封装的post方法，具体大家再看
      if (res.count == 0) that.setData({ count: res.data.count, hasmoreData: false })
      for (var i = 0; i < res.data.list.length; i++) {
        that.data.list.push(res.data.list[i])
      }
      that.setData({ count: res.data.count, num: res.data.num, page: that.data.page + 1, list: that.data.list, hiddenloading: true })
      if (!res.data.hasmoreData) that.setData({ hiddenloading: true })
    })
  },
})